/**
  * Description:
  *      创建一个具有空洞的文件
  */

#include "apue.h"
#include <fcntl.h>

char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";

int main(void) {
    int fd;
    if ((fd = creat("file.hole", FILE_MODE)) < 0)
        err_sys("create error");
    const int size_buf1 = sizeof(buf1) - 1;
    printf("size_buf1: %d\n", size_buf1);
    if (write(fd, buf1, size_buf1) != size_buf1)
        err_sys("buf1 write error");
    /* offset now = 10 */
    if (lseek(fd, 16384, SEEK_SET) == -1)
        err_sys("lseek error");
    /* offset now = 16384 */
    const int size_buf2 = sizeof(buf2) - 1;
    printf("size_buf2: %d\n", size_buf2);
    if (write(fd, buf2, size_buf2) != size_buf2)
        err_sys("buf2 write error");
    /* offset now = 16394 */
    return 0;
}